/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.fb.common;

import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author ngotandieu
 */
public enum ActionType {
    
    PROFILE_ADD(1, "Thêm profile"),
    PROFILE_EDIT(2, "Chỉnh sửa profile"),
    PROFILE_DELETE(3, "Xoá profile"),
    
    POST_ADD(4, "Thêm tin tức profile"),
    POST_EDIT(5, "Chỉnh sửa tin tức profile"),
    POST_DELETE(6, "Xoá tin tức profile"),
    
    CATEGORY_ADD(7, "Thêm danh mục"),
    CATEGORY_EDIT(8, "Chỉnh sửa danh mục"),
    CATEGORY_DELETE(9, "Xóa danh mục"),
    
    ACCOUNT_ADD(10, "Thêm tài khoản"),
    ACCOUNT_EDIT(11, "Chỉnh sửa tài khoản"),
    ACCOUNT_DELETE(12, "Xóa tài khoản"),
    
    ACCOUNT_CHANGE_PASS(13, "Đổi mật khẩu"),
    
    NEWS_CATEGORY_ADD(14, "Thêm danh mục tin tức"),
    NEWS_CATEGORY_EDIT(15, "Chỉnh sửa danh mục tin tức"),
    NEWS_CATEGORY_DELETE(16, "Xóa danh mục tin tức"),
    
    NEWS_ADD(17, "Thêm tin tức"),
    NEWS_EDIT(18, "Chỉnh sửa tin tức"),
    NEWS_DELETE(19, "Xoá tin tức");
    
    
    private int id;
    private String action;

    ActionType(int id, String action) {
        this.id = id;
        this.action = action;
    }

    public int getId() {
        return id;
    }

    public String getAction() {
        return action;
    }

    static final Map<Integer, ActionType> byId = Collections.synchronizedMap(new HashMap<Integer, ActionType>());
    static final Map<String, ActionType> byAction = Collections.synchronizedMap(new HashMap<String, ActionType>());

    static {
        for (ActionType action : EnumSet.allOf(ActionType.class)) {
            byId.put(action.getId(), action);
            byAction.put(action.getAction(), action);
        }
    }

    public static ActionType getById(int id) throws IllegalArgumentException {
        ActionType action = byId.get(id);
        if (action == null) {
            throw new IllegalArgumentException(String.format("Action with ID %s does not exist.", id));
        }
        return action;
    }
}
